package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.impl.conn.DefaultSchemePortResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @author: JC
 * @date: 2021/10/23 10:29
 */
@Api(description = "品牌管理")
@RestController
@RequestMapping("admin/product/baseTrademark/")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    // http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}
    @ApiOperation(value = "分页列表")
    @GetMapping("{page}/{limit}")
    public Result getBaseTradeMarkList(@PathVariable Long page,
                                       @PathVariable Long limit){

        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> iPage = baseTrademarkService.getBaseTradeMarkList(baseTrademarkPage);
        return Result.ok(iPage);
    }

    // http://api.gmall.com/admin/product/baseTrademark/save

    @ApiOperation("新增BaseTrademark")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    @ApiOperation("更新BaseTrademark")
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除BaseTrademark")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
    @ApiOperation("根据Id获取品牌")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
        BaseTrademark trademark = baseTrademarkService.getById(id);
        if(trademark == null){
            return Result.fail();
        }
        return Result.ok(trademark);
    }


    @ApiOperation("获取品牌属性")
    @GetMapping("getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list(null);
        return Result.ok(list);
    }


}
